package com.qf.tenement.tenement_user.controller;

import com.qf.tenement.tenement_entity.ResultData;
import com.qf.tenement.tenement_entity.User;
import com.qf.tenement.tenement_user.service.UserService;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.core.MessagePropertiesBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class UserController {
    @Resource
    private UserService userService;

    @Resource
    private RabbitTemplate rabbitTemplate;

    @PostMapping("/add")
    public ResultData register(User user){
        MessageProperties build = MessagePropertiesBuilder.newInstance().setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN).build();
        return  userService.save(user);
    }

    @PostMapping("/login")
    public ResultData login(User user){
        rabbitTemplate.convertAndSend("en","en",user);
        return  userService.login(user);
    }

    @GetMapping("/check")
    public ResultData check(String token){
        return  userService.check(token);
    }

}
